package com.heima.article.listeren;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.model.article.pojos.ApArticleConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class ArticleListener {
    @Autowired
    private ApArticleConfigMapper apArticleConfigMapper;

    @KafkaListener(topics = "down.Or.Up")
    public void getmassage(String massage){
        Map map = JSON.parseObject(massage, Map.class);
        Long articleId = (Long) map.get("articleId");
        Integer enable = (Integer) map.get("enable");
        ApArticleConfig apArticleConfig = new ApArticleConfig();
        if (enable==0){
            apArticleConfig.setIsDown(true);
        }else {
            apArticleConfig.setIsDown(false);
        }
        LambdaQueryWrapper<ApArticleConfig>wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ApArticleConfig::getArticleId,articleId);
        apArticleConfigMapper.update(apArticleConfig,wrapper);
    }
}
